package com.yogee.topseller.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.yogee.topseller.R;
import com.yogee.topseller.activity.PayActivity;
import com.yogee.topseller.bean.SxrBean;
import com.zly.widget.CollapsedTextView;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * @auathor ${XiaoJianghong}
 * @date 2017/6/26.
 */

public class ZqxxAdapter extends RecyclerView.Adapter<ZqxxAdapter.ItemHolder> {

    private Context context;
    private List<SxrBean.Item> beans = new ArrayList<>();


    private PayActivity.Listener listener;

    public ZqxxAdapter(Context context) {
        this.context = context;
    }

    public void addData(List<SxrBean.Item> beans) {
        this.beans = beans;
        notifyDataSetChanged();
    }

    public void setListener(PayActivity.Listener listener){
        this.listener = listener;
    }

    @Override
    public ItemHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.item_detail_gbbd,null);
        return new ItemHolder(view);
    }

    @Override
    public void onBindViewHolder(ItemHolder holder, final int position) {
        SxrBean.Item bean = beans.get(position);
        SimpleDateFormat sdf=new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        holder.tv_time.setText(sdf.format(new Date(Long.parseLong(String.valueOf(bean.getPublishdate())))));
        holder.tv_value1.setText(bean.getIname());
        holder.tv_value2.setText(bean.getBusinessentity());
        holder.tv_value3.setText(bean.getGistid());
        holder.tv_value4.setText(bean.getAreaname());
        holder.tv_value5.setText(bean.getCardnum());
        holder.tv_value6.setText(bean.getCourtname());
        if(bean.getType()==1)
            holder.tv_value7.setText("公司");
        else
            holder.tv_value7.setText("个人");

        holder.tv_value8.setText(bean.getGistunit());
        holder.tv_value9.setText(bean.getPerformance());
        holder.tv_value10.setText(sdf.format(new Date(Long.parseLong(String.valueOf(bean.getRegdate())))));
        holder.tv_value11.setText(bean.getCasecode());

        if(TextUtils.isEmpty(bean.getDuty())){
            holder.ll1.setVisibility(View.GONE);
        }else{
            holder.ll1.setVisibility(View.VISIBLE);
            holder.tv_detail1.setText(bean.getDuty());
        }
        if(TextUtils.isEmpty(bean.getDisrupttypename())){
            holder.ll2.setVisibility(View.GONE);
        }else{
            holder.ll2.setVisibility(View.VISIBLE);
            holder.tv_detail2.setText(bean.getDisrupttypename());
        }

    }

    @Override
    public int getItemCount() {
        return beans == null ? 0 : beans.size();
    }

    class ItemHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_time)
        TextView tv_time;
        @BindView(R.id.tv_value1)
        TextView tv_value1;
        @BindView(R.id.tv_value2)
        TextView tv_value2;
        @BindView(R.id.tv_value3)
        TextView tv_value3;
        @BindView(R.id.tv_value4)
        TextView tv_value4;
        @BindView(R.id.tv_value5)
        TextView tv_value5;
        @BindView(R.id.tv_value6)
        TextView tv_value6;
        @BindView(R.id.tv_value7)
        TextView tv_value7;
        @BindView(R.id.tv_value8)
        TextView tv_value8;
        @BindView(R.id.tv_value9)
        TextView tv_value9;
        @BindView(R.id.tv_value10)
        TextView tv_value10;
        @BindView(R.id.tv_value11)
        TextView tv_value11;
        @BindView(R.id.ll1)
        LinearLayout ll1;
        @BindView(R.id.ll2)
        LinearLayout ll2;
        @BindView(R.id.tv_detail1)
        CollapsedTextView tv_detail1;

        @BindView(R.id.tv_detail2)
        CollapsedTextView tv_detail2;

        public ItemHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


}